package com.example.wordbook;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;


public class BlankFragment extends Fragment {

    private Dbhelper dbhelper;
    private Dbmanager dbmanager;
    private ListView listView;



    public BlankFragment() {
        // Required empty public constructor
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    private ArrayList<String>words=new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_blank, container, false);
        dbhelper=new Dbhelper(view.getContext());
        dbmanager=new Dbmanager(dbhelper);
        words=dbmanager.getegwords();
        int wordsnum=words.size();
        if(wordsnum==0){
            Toast.makeText(getActivity()
                , "数据库中无数据", Toast.LENGTH_SHORT).show();}
        else {
            listView = view.findViewById(R.id.egwords);
            listView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.support_simple_spinner_dropdown_item, words));
        }

        return view;
    }
}